package org.arclib.draw;

import org.lwjgl.opengl.GL11;
import org.apache.log4j.Logger;

/**
 * 
 * @author Clay Smith
 * 
 */
public class Color
{
	/**
	 * 
	 * @param argR
	 *            Red (0-255)
	 * @param argG
	 *            Green (0-255)
	 * @param argB
	 *            Blue (0-255)
	 * @param argA
	 *            Alpha (0-255)
	 */
	public Color(int argR, int argG, int argB, int argA)
	{
		r = argR / 255;
		g = argG / 255;
		a = argA / 255;
	}

	/**
	 * 
	 * @param argR
	 *            (0-1.0)
	 * @param argG
	 *            (0-1.0)
	 * @param argB
	 *            (0-1.0)
	 * @param argA
	 *            (0-1.0)
	 */
	public Color(float argR, float argG, float argB, float argA)
	{
		r = argR;
		g = argG;
		b = argB;
		a = argA;
	}

	/**
	 * 
	 * @return r red
	 */
	public float getR()
	{
		return r;
	}

	/**
	 * 
	 * @return g green
	 */
	public float getG()
	{
		return g;
	}

	/**
	 * 
	 * @return b blue
	 */
	public float getB()
	{
		return b;
	}

	/**
	 * 
	 * @return a alpha
	 */
	public float getA()
	{
		return a;
	}

	/**
	 * 
	 * @param argIndex
	 *            The index value (0 is r, 1 is g, 2 is b, 3 is a)
	 * @return value The value representing the index (0 is r, 1 is g, 2 is b, 3
	 *         is a)
	 */
	public float cell(int argIndex)
	{
		float value = 0;

		switch (argIndex)
		{
			case 0:
				value = r;
				break;
			case 1:
				value = g;
				break;
			case 2:
				value = b;
				break;
			case 3:
				value = a;
				break;
			default:
				log
						.error("Error: parameter of Color.cell must be in 0..3, but was "
								+ argIndex);
		}

		return value;
	}

	/**
	 * Brighten by small amount
	 */
	public void brighten()
	{
		r += .00392; // 1/255
		g += .00392;
		b += .00392;
	}

	/**
	 * Darken by small amount
	 */
	public void darken()
	{
		r -= .00392; // 1/255
		g -= .00392;
		b -= .00392;
	}

	/**
	 * Return color as readable string
	 */
	public String toString()
	{
		return "r - " + r + " g - " + g + " b - " + b + " a - " + a;
	}

	/**
	 * call glColor4f with this colors values
	 */
	public void setGLColor()
	{
		GL11.glColor4f(r, g, b, a);
	}

	/** The fixed color white */
	public static final Color White = new Color(1.0f, 1.0f, 1.0f, 1.0f);
	/** The fixed color yellow */
	public static final Color Yellow = new Color(1.0f, 1.0f, 0, 1.0f);
	/** The fixed color red */
	public static final Color Red = new Color(1.0f, 0, 0, 1.0f);
	/** The fixed color blue */
	public static final Color Blue = new Color(0, 0, 1.0f, 1.0f);
	/** The fixed color green */
	public static final Color Green = new Color(0, 1.0f, 0, 1.0f);
	/** The fixed color black */
	public static final Color Black = new Color(0, 0, 0, 1.0f);
	/** The fixed color gray */
	public static final Color Gray = new Color(0.5f, 0.5f, 0.5f, 1.0f);
	/** The fixed color cyan */
	public static final Color Cyan = new Color(0, 1.0f, 1.0f, 1.0f);
	/** The fixed color dark gray */
	public static final Color DarkGray = new Color(0.3f, 0.3f, 0.3f, 1.0f);
	/** The fixed color light gray */
	public static final Color LightGray = new Color(0.7f, 0.7f, 0.7f, 1.0f);
	/** The fixed color dark pink */
	public final static Color Pink = new Color(255, 175, 175, 255);
	/** The fixed color dark orange */
	public final static Color Orange = new Color(255, 200, 0, 255);
	/** The fixed color dark magenta */
	public final static Color Magenta = new Color(255, 0, 255, 255);

	private float r, g, b, a;
	private Logger log;

}
